<!DOCTYPE html>
<html lang="zh_CN" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加定时任务</title>
    <header th:replace="header::html"></header>
</head>
<body>
<div class="x-body">
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class='layui-form-item'>
                    <label for="beanName" class='layui-form-label'><span class='x-red'>*</span>bean名称</label>
                    <div class='layui-input-inline'>
                        <input th:value='${sysJob.beanName}' class='layui-input' placeholder='如：testTask'
                               type='text'
                               name='beanName' id='beanName' lay-verify='required'>
                    </div>
                </div>
                <div class='layui-form-item'>
                    <label for='methodName' class='layui-form-label'>
                        <span class='x-red'>*</span>方法名
                    </label>
                    <div class='layui-input-inline'>
                        <input th:value='${sysJob.methodName}' class='layui-input' placeholder="如：getUserName"
                               type='text' name='methodName'
                               id='methodName' lay-verify='required'>
                    </div>
                </div>
                <div class='layui-form-item'>
                    <label for='methodParam' class='layui-form-label'>
                        方法参数
                    </label>
                    <div class='layui-input-inline'>
                        <input th:value='${sysJob.methodParam}' class='layui-input' placeholder='如：value'
                               type='text' name='methodParam'
                               id='methodParam' lay-verify=''>
                    </div>
                </div>
                <div class='layui-form-item'>
                    <label for='cron' class='layui-form-label'>
                        <span class='x-red'>*</span>cron表达式
                    </label>
                    <div class='layui-input-inline'>
                        <input th:value='${sysJob.cron}' class='layui-input' type='text' placeholder="如：0 15 10 * * ? *"
                               name='cron' id='cron'
                               lay-verify='required'>
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <a href="javascript:;" id="cronDetail">常用cron表达式</a>
                    </div>
                </div>
                <div class='layui-form-item'>
                    <label class='layui-form-label'><span class='x-red'>*</span>状态</label>
                    <div class="layui-input-inline">
                        <input type="radio" th:field="${sysJob.status}" name="status" title="启用" value="1" checked>
                        <input type="radio" th:field="${sysJob.status}" name="status" title="禁用" value="2">
                    </div>
                </div>
                <div class='layui-form-item'>
                    <label for="remark" class='layui-form-label'>
                        备注
                    </label>
                    <div class='layui-input-inline'>
                        <textarea th:text='${sysJob.remark}' placeholder="任务描述" class='layui-textarea' name='remark'
                                  id='remark'></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <button class="layui-btn layui-btn-danger" lay-filter="add" lay-submit="">
                        <i class="iconfont">&#xe6ad;</i>立即创建
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        $("#cronDetail").click(function () {
            //配置一个透明的询问框
            layer.msg('每隔5秒执行一次：*/5 * * * * ?\n' +
                '<br>每隔1分钟执行一次：0 */1 * * * ?\n' +
                '<br>每隔5分钟执行一次：0 0/5 * * * ?\n'+
                '<br>每天23点执行一次：0 0 23 * * ?\n' +
                '<br>每天凌晨1点执行一次：0 0 1 * * ?\n' +
                '<br>每天的0点、13点、18点、21点都执行一次：0 0 0,13,18,21 * * ?\n' +
                '<br>每周星期天凌晨1点执行行一次：0 0 1 ? * L' +
                '<br>每月1号凌晨1点执行一次：0 0 1 1 * ?\n' +
                '<br>每月最后一天23点执行一次：0 0 23 L * ?\n', {
                time: 20000,
                btn: ['明白了', '谢谢']
            });
        });

        //监听提交
        form.on('submit(add)', function (data) {
            var status = data.field.status;
            if (status == '2') {
                layer.alert("不允许添加禁用的定时任务");
                return false;
            }
            var loading = layer.load();
            $.ajax({
                url: "/job/saveJob",
                type: "POST",
                data: data.field,
                dataType: 'json',
                success: function (result) {
                    if (result.code == 200) {
                        layer.alert("创建成功", {icon: 6}, function () {
                            xadmin.close();
                            xadmin.father_reload();
                        });
                    } else {
                        layer.close(loading);
                        layer.alert(result.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
